home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
A.C.E. 2
/
ACE CD 2.iso
/
FILES
/
UTILS
/
PROCAL13.DMS
/
PROCAL13.adf
/
Rexx
/
swap.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1991-12-11
|
5KB
|
145 lines
/* Swap S. Dicker 6-Aug-89 */
/* */
/* ARexx program used to swap two columns of cells on an */
/* Advantage spreadsheet. The two columns at the left and right */
/* sides of the currently selected range are exchanged (without */
/* making any adjustments to the cell contents.) */
signal on error /* Trap host command errors. */
address 'Advantage' /* Send commands to Advantage. */
options results /* Enable return of string results. */
'Current' /* Determine current selected range. */
range = result
colon_posn = pos(":",range) /* Look for colon delimiter in range. */
if colon_posn = 0 then /* If no colon, this is not a range. */
do /* Warn the user and then bail out. */
do i = 1 to 100
'DrawMessage'
"Select a range BEFORE using Swap"
end i
exit 10
end
else /* OK - found a colon. Let's do the swap. */
do
/* Save the co-ordinates of the cells at the upper-left and */
/* lower-right corners of the selected range. */
upper = left(range,colon_posn - 1)
lower = substr(range,colon_posn + 1)
/* Extract the labels of the columns to be swapped. */
source1_column = GetColumn(upper)
source2_column = GetColumn(lower)
/* Extract the range of rows to be swapped. */
start_row = GetRow(upper)
end_row = GetRow(lower)
/* Run through all rows, swapping the cell contents */
do rownum = start_row to end_row
call SwapCells(source1_column||rownum,source2_column||rownum)
end rownum
/* Reselect the original range of cells. */
'SelectRange'
value(upper)
value(lower)
end /* End if (range of cells to swap selected) */
exit /* That's all folks! */
/* >>> Host command error handler <<< */
Error:
exit rc /* Just bail out and return error code. */
/* ----------------------------------------------------------------- */
/* Internal Functions (subroutines) */
/* ----------------------------------------------------------------- */
/* == GetRow: Extract the row number from a cell name. == */
GetRow: procedure
arg CellName /* Function expects to be passed a cell name. */
/* Find the first numeric digit in the cell name. */
start_number = verify(CellName,"0123456789","Match")
/* Extract all characters starting at the first digit and continuing */
/* to the end of the cell name. */
rownum = substr(CellName,start_number)
return rownum
/* == GetColumn: Extract the column label from a cell name. == */
GetColumn: procedure
arg CellName /* Function expects to be passed a cell name. */
/* Find the first numeric digit in the cell name. */
start_number = verify(CellName,"0123456789","Match")
/* Extract all characters in the cell name up to the first numeric */
/* character (start of row number). */
column = left(CellName,start_number-1)
return column
/* == GetCell: Extract the contents of a specified cell. == */
GetCell: procedure
arg CellName /* Function expects to be passed a cell name. */
'SelectCell' /* Select the cell whose contents we want. */
value(CellName)
'IsValue' /* Does this cell contain a "value". */
val_flag = result
'IsFormula' /* Does this cell contain a "formula". */
form_flag = result
/* Now extract the cell contents based on what type of data it */
/* contains. NOTE: Order is important here! Formula cells will */
/* return both 'IsValue' = 1 and 'IsFormula' = 1 so that if you */
/* want to treat formula cells as formulas (and not as their */
/* computed values) check if it's a formula before checking if */
/* it's a value. */
select
when form_flag = 1 then /* A Formula ... */
'GetFormula'
when val_flag = 1 then /* ... a Value ... */
'GetValue'
otherwise /* ... or a Label. */
'GetLabel'
end
return result /* Return the cell contents. */
/* == SwapCells: Exchange the contents of two cells. */
SwapCells: procedure
arg cell_1,cell_2 /* Function expects two cell names. */
contents_1 = GetCell(cell_1) /* Extract contents of cell 1. */
contents_2 = GetCell(cell_2) /* Extract contents of cell 2. */
'SelectCell' /* Select cell 1 ... */
value(cell_1)
'PutCell' /* and copy contents of */
contents_2 /* cell 2 into it. */
'SelectCell' /* Select cell 2 ... */
value(cell_2)
'PutCell' /* and copy contents of */
contents_1 /* cell 1 into it. */
return